package com.xinqi.modules.homework.homework.controller.app;

import com.xinqi.common.base.response.R;
import com.xinqi.modules.homework.homework.dto.req.CourseHomeworkRecordUpdateDTO;
import com.xinqi.modules.homework.homework.dto.req.CourseHomeworkStudentDetailDTO;
import com.xinqi.modules.homework.homework.dto.rsp.CourseHomeworkRecordResultDTO;
import com.xinqi.modules.homework.homework.dto.rsp.CourseHomeworkStudentHistoryResultDTO;
import com.xinqi.modules.homework.homework.service.CourseHomeworkRecordService;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.*;

/**
 * 作业学生提交记录APP接口
 *
 * @author: system
 * @date: 2023/03/08
 */
@Tag(name = "App-作业学生提交记录", description = "作业学生提交记录APP接口")
@RestController
@RequestMapping("/app/homework-record")
@RequiredArgsConstructor
public class CourseHomeworkRecordAppController {

    @Lazy
    private final CourseHomeworkRecordService courseHomeworkRecordService;

    /**
     * 提交历史
     *
     * @author: dzy
     * @date: 2023/03/08
     */
    @GetMapping("/list")
    public R<CourseHomeworkStudentHistoryResultDTO> list(CourseHomeworkStudentDetailDTO dto) {
        return R.data(courseHomeworkRecordService.findAll(dto));
    }

    /**
     * 作业学生提交记录-详情-带学生提交文件
     *
     * @author: dzy
     * @date: 2023/03/08
     */
    @GetMapping("/{id}")
    public R<CourseHomeworkRecordResultDTO> findById(@PathVariable("id") Long id) {
        CourseHomeworkRecordResultDTO dto = courseHomeworkRecordService.findById(id);
        return R.data(dto);
    }

    /**
     * 老师批注-学生作业
     *
     * @author: dzy
     * @date: 2023/03/08
     */
    @PostMapping("/annotate")
    public R<Boolean> update(@RequestBody CourseHomeworkRecordUpdateDTO dto) {
        courseHomeworkRecordService.updateById(dto);
        return R.ok("作业批注成功");
    }

}
